package dog.weatherwallpaper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import dog.weatherwallpaper.model.WeatherInfo;
import dog.weatherwallpaper.utils.App;
import dog.weatherwallpaper.utils.Internet;

public final class ConnectivityReceiver extends BroadcastReceiver {
	@Override
	public void onReceive(final Context context, final Intent intent) {
		WeatherInfo wi = WeatherInfo.getInstance();
		if (new Internet().isConnected() && wi.isOldWeather() && wi.update()) {
			LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(App.context());
			lbm.sendBroadcast(new Intent(WPService.DRAW));
			lbm.sendBroadcast(new Intent(MainActivity.RELOAD));
		}
	}
}